<template>
	<view id="bookList">
		<view class="book">
			<view class="book_title">
				<view>
					<image></image>
				</view>
				
				<view>
					<text class="title"></text>
					<text class="author"></text>
					<text class="time"></text>
				</view>
			</view>
			
			<view class="book_list">
				<text class="book_item" v-for="(item, index) in bookList.list[0].list" :key="index">
					{{item.name}}
				</text>
			</view>
		</view>
	</view>
</template>

<script>
	const readBaseUrl = "http://shuapi.jiaston.com/"
	export default {
		data (){
			return {
				bookList: {},
				
				bookId: 0
			}
		},
		mounted() {
			this.getBookList();
		},
		onLoad(option) {
			this.bookId = option.id;
		},
		methods: {
			/**
				 * 获取书籍列表
				 */
				getBookList (){
					let that = this;
					uni.request({
						url: readBaseUrl+"book/"+that.bookId+"/", 
						method: 'get',
						dataType:'json',
						success: res=>{
							// if(res.data.indexOf(",]")!==-1) {
							// 	console.log("enter1")
							// 	// console.log("enters",res.data.indexOf(",]"))
							// 	res.data = res.data.replace(",]","]")
							// 	// console.log("data",res.data)
							// }
							// if(res.data.indexOf(",]")!==-1) {
							// 	console.log("enter")
							// 	res.data = res.data.replace(",]","]")
								
							// }
							res.data = res.data.replace(/\,]/g,']');
							console.log("data1",res.data)
							console.log("data",JSON.parse(res.data))
							that.bookList = JSON.parse(res.data).data;
							console.log(that.bookList)
						},
						error: err=>{
							
						}
					})
				}
		}
	}
</script>

<style lang="scss">
	#bookList{
		padding:16rpx;
		.book{
			.book_list{
				.book_item{
					display: inline-block;
					// flex-direction: row;
					// justify-content: space-between;
					width:46%;
					height: 84rpx;
					font-size:28rpx;
					margin-left:20rpx;
				}
			}
		}
	}
</style>
